<html>
<head>
    <meta charset="UTF-8">
    <title>代码应用模型类型</title>
    <link href="../../static/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../static/easyui/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../../static/easyui/jquery.min.js" type="text/javascript"></script>
    <script src="../../static/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../static/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
    <script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
    <script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
    <script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
    <script src="../../alldic.js"></script>
    <a href="" target="_blank" id="commonLink" name="commonLink"></a>
    <script type="text/javascript">
        $(function() {
            $('#btnQuery').click();
        });
    </script>
</head>

<body class="easyui-layout">
    <div class="easyui-layout" title="" style="width:100%;height:100%;padding:0px;">
        <div data-options="region:'center',split:false" title="" style="width:25%;">
            <!-- <table id="dg" class="easyui-datagrid" title=""
			style="width: 100%; height: 100%"
			data-options="singleSelect:true,collapsible:true,method:'post'"
			title="Load Data" rownumbers="true" pagination="true"
			pageSize="20">
			<thead>
				<tr>
					<th data-options="field:'appTemplateId'" hidden="true">应用模板标识</th>
					<th data-options="field:'appModelType'" width="49%" formatter="formatter_APP_MODEL_TYPE">应用模型类型</th>
					<th data-options="field:'appModelCatalog'" width="50%" formatter="formatter_APP_MODEL_CATALOG">应用模型分类</th>
				</tr>
			</thead>
		</table> -->
            <ul id="nav" class="easyui-tree" data-options="animate:true,
					lines:true,method:'get',
					animate:true" id="menu_app1"></ul>
        </div>
        <div data-options="region:'south',split:false" style="height:30px;text-align:center;padding:0px">
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="doSelect()">选择返回</a>&nbsp;
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="closeForm()">&nbsp;关&nbsp;闭&nbsp;</a>
        </div>
    </div>

    <script>
        function createTree(rows, appModelCatalog) {

            let key = 'appModelType',
                parentKey = 'appModelCatalog',
                childKey = 'children';
            let r = [];
            let tmpMap = {};
            for (i = 0, l = rows.length; i < l; i++) {
                rows[i].id = rows[i][key];
                rows[i].text = formatter_APP_MODEL_TYPE(rows[i][key]);
                tmpMap[rows[i][key]] = rows[i];
			}
			if (rows && rows.length > 0) {
				var root = {};
				root[key] = appModelCatalog;
				root[parentKey] = "0";
				root.id = root[key];
				root.text = formatter_APP_MODEL_CATALOG(appModelCatalog);
				rows.push(root);
				tmpMap[root[key]] = root;
			}
            for (i = 0, l = rows.length; i < l; i++) {
                if (tmpMap[rows[i][parentKey]] && rows[i][key] != rows[i][parentKey]) {
                    if (!tmpMap[rows[i][parentKey]][childKey])
                        tmpMap[rows[i][parentKey]][childKey] = [];
                    tmpMap[rows[i][parentKey]][childKey].push(rows[i]);
                } else {
                    r.push(rows[i]);
                }
            }
            return r;
        }
		var appId = $.getUrlParam('appId');
		var appModelCatalog = $.getUrlParam('appModelCatalog');

		var selection = null;
        $(function() {
            console.log("appId="+appId)
            console.log("appModelCatalog="+appModelCatalog)
            $('#nav').tree({
                queryParams: {
                    appId: appId,
					appModelCatalog: appModelCatalog,
					size: 20
                },
                loader: function(param, success, error) {
                    var url = '../../api/paas/model/infos';
                    $.restfulPostForm(url, param, function(data) {
                        var rows = data.rows;
                        var root = createTree(rows, appModelCatalog);
                        
                        success(root);
                    }, error);
                },
                onClick: function(node) {
                    selection = node;
                },
                
            })
        });

        function doSelect() {
            if (selection) {
                window.parent.setModelTypeVal(selection.appModelType);
                window.parent.JLEUtil.closewin();
            } else {
                $.messager.alert('提示', '请选择一条记录！');
            }
        }

        function closeForm() {
            window.parent.JLEUtil.closewin();
        }
    </script>
</body>

</html>